﻿using System;
using System.Windows.Forms;
using System.Drawing;
using System.Reflection;
using System.IO;

namespace Event.Service
{
    static class Program
    {
#if DEBUG
        /// <summary>
        /// Debug entry point class.
        /// </summary>
        static void Main ()
        {

            NotifyIcon notifyIcon = new NotifyIcon();
            Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream( "Event.Service.Resources.TaskBar.ico" );
            notifyIcon.Icon = new Icon( stream );
            stream.Close();
            notifyIcon.Text = "Event Handler Service";
            notifyIcon.ContextMenu = new ContextMenu();

            var menuItem = new MenuItem();
            menuItem.Index = 0;
            menuItem.Text = "E&xit";
            menuItem.Click += new System.EventHandler( Program.OnExit );
            notifyIcon.ContextMenu.MenuItems.Add( menuItem );

            notifyIcon.Visible = true;

            //Start the service
            MainService service = new MainService();
            service.DebugStart();

            // Start the windows message pump so it can service the tray menu.
            Application.Run();
            notifyIcon.Visible = false;

            //Stop the service
            service.DebugStop();
        }

        static private void OnExit (object Sender, EventArgs e)
        {
            Application.Exit();
        }

#else
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main(string[] args)
        {
            MainService mainService = new MainService();
            string sourceName = "Event Service";
            
            //Change the name of the service if it has a prefix configured.
            if (args.Length > 0)
            {
                mainService.ServiceName = args[0] + ProjectInstaller.ServiceNameBase;
                sourceName += " (" + args[0] + ")";
            }

            ServiceBase.Run(mainService);
        }
#endif
    }
}
